package com.espoir.test;

import com.espoir.pojo.Shp;
import com.espoir.service.IShpService;
import com.espoir.shp.read02.App;
import com.espoir.shp.read02.Point;
import com.espoir.util.JSONUtils;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;

import java.util.ArrayList;
import java.util.List;

@RunWith(SpringRunner.class)
@SpringBootTest
public class ShpApp22 {

    @Autowired
    IShpService shpService;

    @Test
    public void testFindAll() {
        List<Shp> shps = shpService.findAll();
        System.out.println("shp = " + shps);
    }

    /**
     * 测试数据库中的数据到 shp 文件
     */
    @Test
    public void testDBToShpFile() {
        Shp shp = shpService.findById(30);
        String pointArr = shp.getPoint();
        List<Point> points = JSONUtils.StringArrToPoints(pointArr);
        System.out.println("shp = " + shp);
        System.out.println("points = " + points);
        App.writeShp(points,"D:\\test\\test_db_shp");
    }

    /**
     * 测试保存多个点到数据库
     */
    @Test
    public void testSave() {
        Shp shp = new Shp();
        shp.setName("shp测试");
        ArrayList<Point> points = new ArrayList<>();
        points.add(new Point(1,2));
        points.add(new Point(3,2));
        points.add(new Point(5,2));
        String pointsStr = JSONUtils.PointsToString(points);
        shp.setPoint(pointsStr);
        shpService.save(shp);
    }

    @Test
    public void testWrite() {
        Shp shp = shpService.findById(7);
        String p = shp.getPoint();
        Point point = JSONUtils.StringToPoint(p);
    }


    @Test
    public void testWriteShp() {
        JSONUtils.StringArrToPoints("");
    }

    @Test
    public void testPointsToString() {
        ArrayList<Point> points = new ArrayList<>();
        points.add(new Point(1,2));
        points.add(new Point(3,2));
        points.add(new Point(5,2));
        String s = JSONUtils.PointsToString(points);

        List<Point> list = JSONUtils.StringArrToPoints(s);
        String filePath = "D:\\test\\test_shp";
        App.writeShp(list,filePath);
        System.out.println("s = " + s);

    }
}
